<script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
{include file="system@block/layui" /}

<div id="box">
<el-form ref="form" :model="form" label-width="80px"  label-position="left" style='width: 400px; margin-left:50px;'>
  <el-form-item label="会员">
     {{ form.user_name }}
  </el-form-item>
  <el-form-item label="产品名称">
     {{ form.product_name }}
  </el-form-item>
  <el-form-item label="剩余数量">
      <span >{{ (form.product_num_s * 1000  - form.product_num_l * 1000) / 1000}}</span>

  </el-form-item>
  <el-form-item label="领取数量">
	<el-input-number v-model="form.product_num_l"  multiple :min="0">
	</el-input-number>
    <el-tag type="danger">注：如果寄存仓库为总库，领取为分解单位，此处请填写换算小数！如寄存仓库为配料库，此处请勿输入小数！</el-tag>
  </el-form-item>
  <el-form-item label="出货仓库">
        <el-select v-model="form.ware_id" filterable placeholder="请选择仓库">
            <el-option v-for="item,idx in warehouses" :label="item.name" :value="item.id" :key="item.id"></el-option>
    </el-select>
	</el-form-item>

	 <el-form-item label="备注">
	<el-input type="textarea" v-model="form.remark"></el-input>
	</el-form-item>

  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button @click="quxiao">取消</el-button>
  </el-form-item>
  </el-form>
</div>

<script>
var vm = new Vue({
	el:'#box',
	data:{
		form:{
			id:{$formData.id},
			user_id: {$formData.user_id},
			user_name: "{$formData.user_name}",
			product_id: {$formData.product_id},
			product_name: "{$formData.product_name}",
			specs: "{$formData.specs}",
			product_num_s: {$formData.num_s},
			product_num_l: 0,
			remark: '',
            ware_id:'',
		},
        warehouses:{:json_encode($warehouses)},
        
	},
    // created(){
        
    //     console.log(this.warehouses)
    // },
	methods:{
		onSubmit:function(){
			var that = this;
			console.log(this.form)
		    axios.post('{:url('')}', this.form).then(function (response) {
                if(response.data.status === true){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    that.$message({
                        type: 'success',
                        message: response.data.message,
                        onClose: function(){
                            parent.layer.close(index); //再执行关闭
                            // layer.close(layer.index);
                            window.parent.location.reload();
                        }
                    })
                }else{
                    that.$message({
                        type: 'error',
                        message: response.data.message
                    })
                }
            }).catch(function (error) {
                that.$message({
                        type: 'error',
                        message: error
                    })
            });
		},
		quxiao:function(){
			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭
		},
	},

});
</script>
